﻿using System;

using Microsoft.Extensions.DependencyInjection.Extensions;

using RabbitMQSample.WebApi.RabbitMQLibs.Options;

namespace RabbitMQSample.WebApi.RabbitMQLibs
{
    public static class RabbitMqDependencyInjectionExtensions
    {
        public static IServiceCollection AddRabbitMq(this IServiceCollection services, Action<RabbitMqConnectionOptions> configOptions)
        {
            if (configOptions is null)
            {
                throw new ArgumentNullException(nameof(configOptions));
            }

            services.Configure(configOptions);
            services.TryAddSingleton<IRabbitMQConnectionFactory, RabbitMQConnectionFactory>();

            return services;
        }
    }
}
